//
//  FileHandler.m
//  gdemm
//
//  Created by 乔明超 on 16/5/6.
//  Copyright © 2016年 Goldencis. All rights reserved.
//

#import "FileHandler.h"
#import "FileUtil.h"
#import "NativeEncrypt.h"
#import "TempFileManager.h"
@interface FileHandler()
@property (nonatomic,copy) NSString *mError;
@end

@implementation FileHandler

- (NSString *)getDecryptedPath:(NSString *)filePath{
    if (![FileUtil isFileExistWithFilePath:filePath]) {
        self.mError = @"文件不存在";
        return nil;
    }
    NSString *path;
    if (![NativeEncrypt isEncryptedFile:filePath]) {
        NSString *privatepath = [[TempFileManager getInstance] getPrivateTmpDirWihtFileNme:[filePath lastPathComponent]];
        if ([NativeEncrypt decrytFileFromPath:filePath toPath:privatepath]) {
            self.mError = @"没有正确的授权，无法打开加密文件";
        }else{
            path = privatepath;
        }
    }else{
        path = filePath;
    }
    return path;
}

- (NSString *)getErrorInfo{
    return self.mError;
}

- (BOOL)isSupportedType:(NSString *)suffix{
    return NO;
}

- (UIViewController *)getControllerForFilePath:(NSString *)filePath{
    return nil;
}

- (NSString *)getIconWithFileName:(NSString *)fileName enced:(BOOL)isEnced{
    return nil;
}
@end
